//刷新验证码
function refreshCheckCode(id){
	  $("#"+id).attr({"src":"randomCode?random="+new Date()});
}

//刷新验证码
function refreshCheckCode1(id){
	  $("#"+id).attr({"src":"user/randomCode?random="+new Date()});
}

function isEmail(str){ 
	var reg = /^([.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/; 
	return reg.test(str); 
}
//6位数以上字母或者数字
function pwdCheck(str){
	var reg = /^[a-zA-Z0-9]{6,99}/;
	return reg.test(str);
}

var wait=60;

//type;验证类型(邮件、短信)
//category;分类 (注册、提现 、转账 )
//authStr;验证的类型(手机号或邮件地址)
function getVerificationCode(type,category,inputId,butId,isLogin){
	var inputValue = $(inputId).val();
	wait =60;
	if(type=='Email'){
		if(inputValue==''){
			alert('邮箱不允许为空!');
			$(inputId).focus();
			return false;
		}
		if(isEmail(inputValue)){
			$(inputId+"_show").text('邮箱验证码正在获取中....');
			$.post('activationCode!getEmailActivationCode.action',
					'dto.type='+type+'&dto.category='+category+'&dto.authStr='+$(inputId).val(),function(){
				//$(inputId+"_show").text('Has successfully sent, please note that check the garbage box(已发送成功，请注意检查垃圾收件箱)!');
				alert('验证码已成功发送到您的邮件地址，请查收，谢谢!');
				time(butId);
			});
		}else{
			alert('邮件地址无效，请检查!');
			return false;
		}
	}else if(type=='Mobile'){
		
		if(inputValue==''){
			alert('手机号码或登录账号不允许为空!');
			$(inputId).focus();
			return false;
		}
		
		if(isLogin || checkMobile(inputValue)){
			$.post('activationCode!getEmailActivationCode.action','dto.type='+type+'&dto.category='+category+'&dto.authStr='+$(inputId).val(),function(){
				//$(inputId+"_show").text('Has successfully sent, please note that check the garbage box(已发送成功，请注意检查垃圾收件箱)!');
				alert('已将验证码发送到您的手机号码,请查收!');
				time(butId);
			});
		}else{
			alert('手机号码无效，请检查!');
			return false;
		}
	}
}


function time(id) {
    if (wait == 0) {
    	$(id).attr("disabled", false);          
    	$(id).val("获取验证码");
        wait = 60;
    } else { 
    	$(id).attr("disabled", true);
    	$(id).val(wait+"秒后重新获取"); 
        wait--; 
        setTimeout(function(){
        	time(id);      
        },1000);
    } 
} 
function hasText(str) {
	if (str && str.length > 0) {
		return true;
	}
	return false;
}

function checkMobile(str) {
   var re = /^1\d{10}$/;
   if (re.test(str)) {
       return true;
   } else {
	   return false;
   }
}

function setCookie(c_name, value, exdays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value = escape(value)
			+ ((exdays == null) ? "" : "; expires="
					+ exdate.toUTCString());
	document.cookie = c_name + "=" + c_value;
}
function setLanguage(lang) {
	setCookie('language', lang, 300);
	window.top.location.reload();
}

